package com.ruiysoft.util;

import org.apache.commons.lang3.RandomStringUtils;

import java.util.Date;
import java.util.Random;
import java.util.UUID;

/**
 * Date : 2018/11/10
 *
 * @author WenJialu
 */
public enum CodeGenerator {

	INSTANCE;

	private final Random random = new Random();

	public String genOrderNoCustomerPlace(){
		return genOrderNo("CP", null);
	}

	public String genOrderPaySysTransactionNo(){
		return "PT" + genTimeFormat() + genRandomString(6);
	}

	public String gen32UUID(){
		return UUID.randomUUID().toString().replace("-", "");
	}



	public String genOrderNo(String prefix, String suffix) {
		prefix = null == prefix ? "AGE" : prefix;
		suffix = null == suffix ? "" : suffix;
		return prefix + genTimeFormat() + suffix + genRandomNum(3);
	}

	public String genTimeFormat(){
		return DateFormatUtil.INSTANCE.SDF_ONLY_NUM_UNTIL_SECOND.format(new Date());
	}

	public String genRandomString(int length) {
		return RandomStringUtils.random(length, true, false);
	}

	public String genRandomNum(int length){
		return RandomStringUtils.randomNumeric(length);
		/*StringBuilder builder = new StringBuilder();
		for (int i = 0; i < length; i++) {
			builder.append(random.nextInt(10));
		}
		return builder.toString();*/
	}
}
